<?php

require_once './library/Zend/Db/Table/Abstract.php';

class logFilters extends Zend_Db_Table
{

    protected $_name;
    protected $_primary;
    protected $_db;
    protected $_registery;
    private $_select;

    protected function _setup()
    {
        $this->_name = 'logfilters';
        $this->_primary = 'IdFilter';
        $this->_registry = Zend_Registry::getInstance();
        $this->_db = $this->_registry->get('adapter');
        parent::_setup();
    }

    public function getLogFilter($name)
    {
        $this->_select = $this->_db->select();
        $this->_select->from($this->_name);
        $this->_select->where('NameFilter = ?', $name);
        $this->_select = $this->_db->query($this->_select);
        $result = $this->_select->fetchAll();
        if (isset($result[0]))
            return $result;
        return false;
    }

    public function listLogFilter()
    {
        $this->_select = $this->_db->select();
        $this->_select->from($this->_name);
        $this->_select = $this->_db->query($this->_select);
        $result = $this->_select->fetchAll();
        if (isset($result[0]))
            return $result;
        return false;
    }

    public function newLogFilter($name, $filter)
    {
        $val = array('NameFilter' => $name,
            'Filter' => $filter);
        $this->_db->insert($this->_name, $val);
        return true;
    }

    public function updateLogFilter($name, $filter)
    {
        $val = array('Filter' => $filter);
        $where = $this->_db->quoteInto('namefilter = ?', $name);
        $this->_db->update($this->_name, $val, $where);
        return true;
    }

    public function deleteLogFilter($name)
    {
        $this->delete($this->_db->quoteInto('namefilter = ?', $name));
    }

}
?>